package view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import model.Player;

public class DiceFrame extends JFrame {

	/**
	 * 
	 */
	//private static final long serialVersionUID = 1L;
	private Player player;
	/**
	 * A new Frame that sets the players Dice Options
	 * @param Player p
	 */
	public DiceFrame(Player p){
		player = p;
		this.setTitle("Set Dice Preferences");
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setMinimumSize(new Dimension(300,100));
        this.setLocationRelativeTo(null);
        //this.setMinimumSize(new Dimension(300,200));
        //this.setMaximumSize(new Dimension(300,200));
        this.setLayout(new BorderLayout());
        
		
		//this.add(image, BorderLayout.CENTER);
		
		JRadioButton oneA = new JRadioButton("One");
		oneA.addActionListener(new AttackDiceListener(1));
		JRadioButton twoA = new JRadioButton("Two");
		twoA.addActionListener(new AttackDiceListener(2));
		JRadioButton threeA = new JRadioButton("Three");
		threeA.addActionListener(new AttackDiceListener(3));
		
		JRadioButton oneD = new JRadioButton("One");
		oneD.addActionListener(new DefendDiceListener(1));
		JRadioButton twoD = new JRadioButton("Two");
		twoD.addActionListener(new DefendDiceListener(2));
		
		ButtonGroup attackGroup = new ButtonGroup();
		attackGroup.add(oneA);
		attackGroup.add(twoA);
		attackGroup.add(threeA);
		
		ButtonGroup defendGroup = new ButtonGroup();
		defendGroup.add(oneD);
		defendGroup.add(twoD);
		
		JPanel attackButtons = new JPanel();
		attackButtons.add(new JLabel("Attack Dice"));
		attackButtons.add(oneA);
		attackButtons.add(twoA);
		attackButtons.add(threeA);
		
		JPanel defendButtons = new JPanel();
		defendButtons.add(new JLabel(new ImageIcon("images/dice.png")));
		defendButtons.add(new JLabel("Defend Dice"));
		defendButtons.add(oneD);
		defendButtons.add(twoD);
		
		//ImageIcon image = new ImageIcon("images/dice.png");
		
		this.add(attackButtons, BorderLayout.NORTH);
		this.add(defendButtons, BorderLayout.CENTER);
        
        this.setVisible(true);
	}
	private class AttackDiceListener implements ActionListener{
		private int number;
		public AttackDiceListener(int num){
			number = num;
		}
		
		@Override
		public void actionPerformed(ActionEvent arg0) {
			player.setDiceAttack(number);
			System.out.println("Attack: "+number);
		}
		
	}
	private class DefendDiceListener implements ActionListener{
		private int number;
		public DefendDiceListener(int num){
			number = num;
		}
		
		@Override
		public void actionPerformed(ActionEvent arg0) {
			player.setDiceDefend(number);
			System.out.println("Defend: "+number);
						
		}
		
	}
}
